# score.py

r'''These all return a three-tuple:

    - the score for this answer
    - the max score
    - the (category, question) that still needs to be asked, or None (if the
      question has already been asked).
'''

from naimath.engine import engine

def got(category, question, **answers):
    with engine.Engine.prove_goal("%s.%s($answer)" % (category, question)) \
      as gen:
        score = 0.0
        found = False
        for vars, plan in gen:
            score += answers.get(vars['answer'], 0.0)
            found = True
    max_score = max(answers.itervalues())
    return score, max_score, (None if found else (category, question))

def not_(category, question, answer, score):
    with engine.Engine.prove_goal("%s.%s($answer)" % (category, question)) \
      as gen:
        found = False
        for vars, plan in gen:
            if vars['answer'] == answer:
                return 0, score, None
            found = True
    if found:
        return score, score, None
    return 0, score, (category, question)

